﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace example03
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void rbnCong_CheckedChanged(object sender, EventArgs e)
        {
            if (rbnCong.Checked == true)
            {
                btnCong.Text = "Cộng";
            }
        }

        private void rbnTru_CheckedChanged(object sender, EventArgs e)
        {
            if (rbnTru.Checked == true)
            {
                btnCong.Text = "Trừ";
            }
        }

        private void rbnNhan_CheckedChanged(object sender, EventArgs e)
        {
            if (rbnNhan.Checked == true)
            {
                btnCong.Text = "Nhân";
            }
        }

        private void rbnChia_CheckedChanged(object sender, EventArgs e)
        {
            if (rbnChia.Checked == true)
            {
                btnCong.Text = "Chia";
            }
        }

        private void btnCong_Click(object sender, EventArgs e)
        {
            float a = int.Parse(txtSoA.Text);
            float b = int.Parse(txtSoB.Text);
            float c = 0;
            if (rbnCong.Checked == true)
            {
                c = a + b;
            }
            if (rbnTru.Checked == true)
            {
                c = a - b;
            }
            
            if (rbnNhan.Checked == true)
                {
                    c = a * b;
                }
            if(rbnChia.Checked==true)
                if (b == 0)
                {
                    MessageBox.Show("Error!", "Warning", MessageBoxButtons.OK);
                }
                else

                {
                    c = a / b;
                }
            txtKq.Text = c.ToString();
        }

        
    }
}
